﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sprite_Editor
{
    class tVector2D
    {
        public tVector2D()
        {

        }

        public tVector2D( float X, float Y )
        {
            this.fX = X;
            this.fY = Y;
        }

        public tVector2D(double X, double Y)
        {
            this.fX = (float)X;
            this.fY = (float)Y;
        }

        private float fX;
        public float FX
        {
            get { return fX; }
            set { fX = value; }
        }

	    float fY;

        public float FY
        {
            get { return fY; }
            set { fY = value; }
        }

        public static tVector2D operator+ ( tVector2D v1, tVector2D v2 )
	    {
		    return new tVector2D( v1.fX + v2.fX, v1.fY + v2.fY );
	    }

	    public static tVector2D operator- ( tVector2D v1, tVector2D v2 )
	    {
		    return new tVector2D( v1.fX - v2.fX, v1.fY - v2.fY );
	    }

	    public static tVector2D operator* ( tVector2D v1, float f )
	    {
		    return new tVector2D( v1.fX * f, v1.fY * f );
	    }

        public static tVector2D operator /(tVector2D v1, float f)
	    {
		    return new tVector2D( v1.fX / f, v1.fY / f );
	    }

        public static tVector2D Vector2DRotate(tVector2D vec, float fRadians)
        {
            vec.fY *= -1;

            tVector2D returnvec = new tVector2D(Math.Cos(fRadians) * vec.fX + Math.Sin(fRadians) * vec.fY, (-Math.Sin(fRadians)) * vec.fX + Math.Cos(fRadians) * vec.fY);

            vec.fY *= -1;

            return returnvec;
        }
        
        public static tVector2D Vector2DNormalize( tVector2D vector )
        {
            float Length = (float)Math.Sqrt( (vector.FX * vector.FX) + (vector.FY * vector.FY) );
            return new tVector2D(vector.FX / Length, vector.FY / Length);
        }

        public static float DegreesToRadians(float degrees)
        {
            return degrees * (float)Math.PI / 180;
        }
    }
}
